package part1.api.io.mytest;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;

/**
 * 转换流
 */
public class OSWDemo {
    public static void main(String[] args) {
        try (
                FileOutputStream fos = new FileOutputStream("bw.txt");
                OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        ) {
            osw.write("你好世界");
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("转换流写出成功");
        try (
                FileInputStream fis = new FileInputStream("bw.txt");
                InputStreamReader isr = new InputStreamReader(fis,StandardCharsets.UTF_8)
        ) {
            int d;
            while ((d = isr.read()) != -1){
                System.out.print((char) d);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
